import axios from 'axios';
import Storage from '../utils/localStorage';
import { Message, MessageBox } from 'element-ui';
const service = axios.create({
    // process.env.NODE_ENV === 'development' 来判断是否开发环境
    // easy-mock服务挂了，暂时不使用了
    // baseURL: 'http://192.168.0.12:8080/ddw',
    baseURL: 'https://www.dazhimu.cc/',
    timeout: 50000

    // paramsSerializer: function(params) {
    //     console.log(params);xxx
    // }
});
service.interceptors.request.use(
    config => {
      config.headers.Authorization = Storage.getItem('token') ? Storage.getItem('token') : '1';
      return config;
    },
    error => {
      console.log(error);
      return Promise.reject();
    }
);
service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            if (response.data.code === '-4003') {
                window.location.href = 'https://www.dazhimu.cc/sys/index.html#/login';
            }
            return response.data;
        } else {
            return Promise.reject();
        }
    },
    error => {
        Message.error('系统错误');
        console.log(error);
        return Promise.reject();
    }
);

export default service;
